clear all
set more off
cd "/Users/yasenov/Dropbox (IPL)/RefugeeBan/data/"

***********
***********
***********

use "WRAPS/wraps_fips.dta"
keep if year >= 2010

merge 1:1 fips year using "crime/crime.dta", keep(1 3) keepusing(property violent cleared*)
drop if _merge == 1    
drop _merge

merge 1:1 fips year using "demographics/demographics.dta", keep(1 3)
drop if _merge == 1    
drop _merge

merge 1:1 fips year using "county_adjacency/county_adjacency_crime.dta", keep(1 3)
drop _merge

gen lproperty_crime = log(property_crime + 1)
gen rproperty_crime = (property_crime / pop_total) * 100000

gen lviolent_crime = log(violent_crime + 1)
gen rviolent_crime = (violent_crime / pop_total) * 100000

* treatment vars for year 2016
gen lrefugees2016 = log(refugees + 1)
gen rrefugees2016 = (refugee / pop_total) * 100

sort fips year
bysort fips: replace lrefugees2016 = lrefugees2016[7]
bysort fips: replace rrefugees2016 = rrefugees2016[7]

destring fips, replace
destring fips_state, replace

gen s_movers = (pop_moved_in_1_yr_ago / pop_total) * 100000
gen l_movers = log(pop_moved_in_1_yr_ago+1)

gen s_clr_property = cleared_property_crime / property_crime
gen s_clr_violent = cleared_violent_crime / violent_crime

replace pop_total = log(pop_total)
*replace pop_density = log(pop_density)

**************
**************

gen dd = (year >= 2017) * rrefugees2016
gen dd_log = (year >= 2017) * lrefugees2016

label var dd "Diff-in-Diff"
label var dd_log "Diff-in-Diff"

global trends i.fips#c.year
xtset fips year

**************
************** MAIN SPECIFICATION
**************

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
	
**************
************** ADDING CONTROLS
**************

global options cluster(fips_state)  
global weight 
global controls pop_total s_black s_white s_hisp s_hs_dropout s_hs_grad s_unempl s_not_in_lf s_male_age_15_34

eststo clear
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_controls.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))

**************
************** SUBSET TO URBAN COUNTIES
**************

global options cluster(fips_state)  
global weight 
global controls 

/***  identify urban areas ***/
preserve
collapse pop_dens, by(fips)
qui sum pop_density, d

gen urban = pop_density >= r(p50)
tab urban, m

keep fips urban
tempfile fileurban
save `fileurban'
restore

merge m:1 fips using `fileurban'
/*				*/

preserve
keep if urban == 1
eststo clear
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_urban.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))

	restore
	
**************
************** WEIGHTED REGRESSIONS
**************

global options cluster(fips_state)  
global weight [aw = pop_total]
global controls 

eststo clear
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_weighted.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))

**************
************** LEAD CRIME AS OUTCOME
**************

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe f.rproperty_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe f.rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe f.rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe f.rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe f.lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe f.lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe f.lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe f.lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_lead.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
	
**************
************** SHARE MALE POLICE AS OUTCOME
**************	

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe s_police_male dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_police_male dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe s_police_male dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_police_male dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm


esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Share Male Police" "Share Male Police" "Share Male Police" "Share Male Police") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_share_male_police.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Share Male Police" "Share Male Police" "Share Male Police" "Share Male Police") ///
	scalars("trends County Trends") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
	
**************
************** SHARE IN-MOVERS AS OUTCOME
**************	

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe s_movers dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_movers dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe l_movers dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe l_movers dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm


esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Share In-movers" "Share In-movers" "Log $\#$ In-movers" "Log $\#$ In-movers") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_share_movers.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Share In-movers" "Share In-movers" "Log $\#$ In-movers" "Log $\#$ In-movers") ///
	scalars("trends County Trends") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
	
**************
************** SHARE CLEARED CRIMES AS OUTCOME
**************

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe s_clr_property dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_clr_property dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe s_clr_violent dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_clr_violent dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe s_clr_property dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_clr_property dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe s_clr_violent dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe s_clr_violent dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_clread_crimes.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
		
**************
************** COMMON SUPPORT ASSUMPTION
**************

global options cluster(fips_state)  
global weight 
global controls 

preserve
collapse *2016, by(fips*)
sum rrefug, d
gen treat = rrefug > r(p50)
tab fips_state treat
restore

preserve
drop if inlist(fips_state, 10, 15, 32, 56)
global options cluster(fips_state)  
global weight 

eststo clear
eststo: reghdfe rproperty_crime  dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_commonsupport.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))
restore	


**************
************** CONTROL FOR SPATIAL AVERAGE CRIME
**************

global options cluster(fips_state)  
global weight 
global controls 

eststo clear
eststo: reghdfe rproperty_crime dd rproperty_crime_neighbor $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd rproperty_crime_neighbor $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd lviolent_crime_neighbor $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd lviolent_crime_neighbor $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log lproperty_crime_neighbor $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log lproperty_crime_neighbor $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log rviolent_crime_neighbor $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log rviolent_crime_neighbor $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_spatialcrime.tex", replace label ///
	keep(dd dd_log) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label("County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)" ) fmt(%4.0f %4.0f %4.3f %4.1f))


**************
************** USE ALL US COUNTIES
**************

clear
use "WRAPS/wraps_fips.dta", clear
keep if year >= 2010

merge 1:1 fips year using "crime/crime.dta", keepusing(property violent) gen(m1)

merge 1:1 fips year using "demographics/demographics.dta", keep(1 3) gen(m2)

replace refugees = 0 if mi(refugees)

order fips* year ref *crime pop_total
sum

**************
**************

/*** treatment vars for year 2016  ***/

preserve
keep if year == 2016
keep refugees fips pop_total

gen lrefugees2016 = log(refugees + 1)
gen rrefugees2016 = (refugee / pop_total) * 100

gen group = .
replace group = 1 if rrefugees2016 == 0

sum rrefugees2016 if rrefugees2016 > 0, d
replace group = 2 if rrefugees2016 <= r(p50) & rrefugees2016 > 0
replace group = 3 if rrefugees2016 > r(p50) & rrefugees2016 > 0

tab group, m

tempfile filegroups
save `filegroups'
restore

merge m:1 fips using `filegroups'

**************
**************

gen lproperty_crime = log(property_crime + 1)
gen rproperty_crime = (property_crime / pop_total) * 100000

gen lviolent_crime = log(violent_crime + 1)
gen rviolent_crime = (violent_crime / pop_total) * 100000

destring fips, replace
destring fips_state, replace

**************
**************

gen dd1 = (year >= 2017) * (group == 1)
gen dd2 = (year >= 2017) * (group == 2)

gen dd_log1 = (year >= 2017) * (group == 1)
gen dd_log2 = (year >= 2017) * (group == 2)

global options cluster(fips_state)  
global weight 
global trends i.fips#c.year
global controls 

label var dd1 "No Refugees $\times$ Post"
label var dd2 "Low Refugees $\times$ Post"

label var dd_log1 "No Refugees $\times$ Post"
label var dd_log2 "Low Refugees $\times$ Post"

eststo clear
eststo: reghdfe rproperty_crime dd1 dd2 $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rproperty_crime dd1 dd2 $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe rviolent_crime dd1 dd2 $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe rviolent_crime dd1 dd2 $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

eststo: reghdfe lproperty_crime dd_log1 dd_log2 $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lproperty_crime dd_log1 dd_log2 $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm
eststo: reghdfe lviolent_crime dd_log1 dd_log2 $controls $weight, $options absorb(year fips)
estadd local trends ""
estadd ysumm
eststo: reghdfe lviolent_crime dd_log1 dd_log2 $controls $weight, $options absorb(year fips $trends)
estadd local trends "X"
estadd ysumm

esttab, label ///
	keep(dd1 dd2 dd_log1 dd_log2) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("trends County Trends") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_cdid_allcounties.tex", append label ///
	keep(dd1 dd2 dd_log1 dd_log2) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("trends County Trends") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(trends N r2 ymean ysd , label( "County Trends" "N" "R$^2$" "$\bar{Y}$" "sd(Y)") fmt(%4.0f %4.0f %4.3f %4.1f))
